-- story_conflict.lua - 修仙游戏冲突和战斗相关故事

return {
    -- 接受任务节点
    {
        id = "accept_quest",
        title = "接受任务",
        text = [[村长对你的决定表示感谢，并给了你一些补给。
'小心点，那些野兽很凶猛。']],
        vars = {
            ["player.gold"] = function(state)
                return (state.variables["player.gold"] or 0) + 20
            end,
            ["game.quest_accepted"] = true,
            ["game.score"] = function(state)
                return (state.variables["game.score"] or 0) + 15
            end
        },
        choices = {
            {
                text = "立即前往山林",
                next = "mountain_forest"
            },
            {
                text = "先准备一下",
                next = "prepare_for_quest"
            }
        }
    },
    
    -- 拒绝任务节点
    {
        id = "refuse_quest",
        title = "拒绝任务",
        text = [[村长有些失望，但还是理解了你的决定。
'希望你能改变主意，村里真的需要帮助。']],
        vars = {
            ["game.quest_refused"] = true,
            ["game.score"] = function(state)
                return (state.variables["game.score"] or 0) - 5
            end
        },
        choices = {
            {
                text = "改变主意，接受任务",
                next = "accept_quest"
            },
            {
                text = "回家修炼",
                next = "start_cultivation"
            }
        }
    },
    
    -- 询问任务详情节点
    {
        id = "ask_quest_details",
        title = "任务详情",
        text = [[村长告诉你，野兽主要在山林的西边活动。
它们体型巨大，力大无穷，已经伤了好几个村民。
你需要杀死至少三只野兽才能解决问题。]],
        vars = {
            ["game.quest_details"] = "beast_details",
            ["game.score"] = function(state)
                return (state.variables["game.score"] or 0) + 5
            end
        },
        choices = {
            {
                text = "接受任务",
                next = "accept_quest"
            },
            {
                text = "拒绝任务",
                next = "refuse_quest"
            }
        }
    },
    
    -- 追踪声音来源节点
    {
        id = "track_sound",
        title = "追踪野兽",
        text = [[你顺着声音追踪，发现了三只巨大的野猪。
它们正在破坏一片竹林，看起来非常愤怒。]],
        vars = {
            ["game.enemy"] = "giant_boars",
            ["game.score"] = function(state)
                return (state.variables["game.score"] or 0) + 10
            end
        },
        choices = {
            {
                text = "主动攻击",
                next = "fight_boars"
            },
            {
                text = "悄悄观察",
                next = "observe_boars"
            },
            {
                text = "返回村庄报告",
                next = "report_to_village"
            }
        }
    },
    
    -- 与野猪战斗节点
    {
        id = "fight_boars",
        title = "野猪之战",
        text = function(state)
            local cultivation = state.variables["player.cultivation"]
            if cultivation == "练气一层" then
                return [[你与野猪展开了激烈的战斗。
虽然你修为不高，但凭借着修仙者的优势，你勉强击败了一只野猪。
但剩下的两只野猪让你感到力不从心。]]
            elseif cultivation == "练气二层" then
                return [[你与野猪展开了激烈的战斗。
凭借着练气二层的修为，你成功击败了两只野猪。
第三只野猪见势不妙，逃跑了。]]
            else
                return [[你与野猪展开了战斗。
凭借着强大的修为，你轻松击败了所有三只野猪。
战斗结束后，你感到有些疲惫，但收获满满。]]
            end
        end,
        vars = function(state)
            local cultivation = state.variables["player.cultivation"]
            local result = {
                ["player.health"] = function(state)
                    return math.max(1, (state.variables["player.health"] or 100) - 20)
                end
            }
            
            if cultivation == "练气一层" then
                result["game.boars_killed"] = 1
                result["game.score"] = function(state)
                    return (state.variables["game.score"] or 0) + 20
                end
            elseif cultivation == "练气二层" then
                result["game.boars_killed"] = 2
                result["game.score"] = function(state)
                    return (state.variables["game.score"] or 0) + 35
                end
            else
                result["game.boars_killed"] = 3
                result["game.quest_completed"] = true
                result["game.score"] = function(state)
                    return (state.variables["game.score"] or 0) + 50
                end
            end
            
            return result
        end,
        choices = {
            {
                text = "继续寻找野兽",
                next = "continue_hunting"
            },
            {
                text = "返回村庄",
                next = "return_to_village"
            },
            {
                text = "原地休息",
                next = "rest_in_forest"
            }
        }
    },
    
    -- 寻找草药节点
    {
        id = "find_herbs",
        title = "发现草药",
        text = [[你在山林中找到了一些珍贵的草药。
这些草药可以用来炼制丹药，提升修为。]],
        vars = {
            ["player.herbs"] = function(state)
                return (state.variables["player.herbs"] or 0) + 5
            end,
            ["game.score"] = function(state)
                return (state.variables["game.score"] or 0) + 10
            end
        },
        choices = {
            {
                text = "继续寻找",
                next = "find_more_herbs"
            },
            {
                text = "返回村庄",
                next = "village_outside"
            },
            {
                text = "尝试炼制丹药",
                next = "attempt_alchemy"
            }
        }
    },
    
    -- 购买补气丹节点
    {
        id = "buy_qi_pill",
        title = "购买补气丹",
        text = function(state)
            local gold = state.variables["player.gold"] or 0
            if gold >= 5 then
                return [[你花费5金币购买了一瓶补气丹。
'这丹药可以快速恢复你的灵气，关键时刻很有用。']]
            else
                return [[你身上的金币不够，无法购买补气丹。
'下次再来吧，年轻人。']]
            end
        end,
        vars = function(state)
            local gold = state.variables["player.gold"] or 0
            if gold >= 5 then
                return {
                    ["player.gold"] = gold - 5,
                    ["player.qi_pills"] = function(state)
                        return (state.variables["player.qi_pills"] or 0) + 1
                    end,
                    ["game.score"] = function(state)
                        return (state.variables["game.score"] or 0) + 5
                    end
                }
            else
                return {
                    ["game.score"] = function(state)
                        return (state.variables["game.score"] or 0) - 2
                    end
                }
            end
        end,
        choices = {
            {
                text = "继续购买其他物品",
                next = "buy_herbs"
            },
            {
                text = "离开药铺",
                next = "village_outside"
            }
        }
    },
    
    -- 购买疗伤药节点
    {
        id = "buy_healing_pill",
        title = "购买疗伤药",
        text = function(state)
            local gold = state.variables["player.gold"] or 0
            if gold >= 3 then
                return [[你花费3金币购买了一瓶疗伤药。
'这药可以快速恢复你的伤势，记得随身携带。']]
            else
                return [[你身上的金币不够，无法购买疗伤药。
'下次再来吧，年轻人。']]
            end
        end,
        vars = function(state)
            local gold = state.variables["player.gold"] or 0
            if gold >= 3 then
                return {
                    ["player.gold"] = gold - 3,
                    ["player.healing_pills"] = function(state)
                        return (state.variables["player.healing_pills"] or 0) + 1
                    end,
                    ["game.score"] = function(state)
                        return (state.variables["game.score"] or 0) + 5
                    end
                }
            else
                return {
                    ["game.score"] = function(state)
                        return (state.variables["game.score"] or 0) - 2
                    end
                }
            end
        end,
        choices = {
            {
                text = "继续购买其他物品",
                next = "buy_herbs"
            },
            {
                text = "离开药铺",
                next = "village_outside"
            }
        }
    }
}